package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("permission")
@RestController
public class PermissionController {
	@DubboReference
	PermissionService permissionService;
/**
 * @Author: wty 
 * @Date: 18:21 2021/3/11
 * @Parms []
 * @ReturnType: com.itheima.health.entity.Result
 * @Description: 查询所有的权限
*/
	@GetMapping("findAll")
	public Result findAll() {
		List<Permission> permissionList = permissionService.findAll();
		return new Result(true, "查询所有的权限成功", permissionList);
	}
	@GetMapping("findPage")
	public Result findPgae(QueryPageBean queryPageBean) {
		log.info("[菜单---分页查询]data: {}",queryPageBean);
		PageResult pageResult = permissionService.findPage(queryPageBean);

		return new Result(true, MessageConst.QUERY_MENU_SUCCESS,pageResult);
	}

	@PostMapping("add")
	public Result add(@RequestBody Permission permission) {
		log.info("[菜单---添加]data: {}",permission);
		permissionService.add(permission);
		return new Result(true,MessageConst.ADD_MENU_SUCCESS);
	}

	@PostMapping("delete")
	public Result deleteById(Integer id) {
		log.info("[菜单---删除]data: {}", id);
		permissionService.delete(id);
		return new Result(true,MessageConst.DELETE_MENU_SUCCESS);

	}
	@GetMapping("findById")
	public Result findById(Integer id) {
		log.info("[菜单---根据id查询]data: {}", id);
		Permission permission = permissionService.findById(id);
		return new Result(true,MessageConst.QUERY_MENU_SUCCESS,permission);
	}

	@PostMapping("update")
	public Result edit(@RequestBody Permission permission) {
		log.info("[菜单---修改]data: {}",permission);
		permissionService.edit(permission);
		return new Result(true, MessageConst.EDIT_MENU_SUCCESS);
	}
	@GetMapping("findcheckitemIdsById")
	public Result findcheckitemIdsById(Integer id) {
		CheckItem checkItem = new CheckItem();
		Integer checkItemId = checkItem.getId();
		log.info("[菜单---根据检查项id查询菜单项]data: {}",checkItemId);
		Permission permission= permissionService.findcheckitemIdsById(checkItemId);
		return new Result(true,MessageConst.QUERY_MENU_SUCCESS,permission);

	}

}
